package cn.lls.base.exception;


import cn.lls.base.result.ResultCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 自定义全局异常类
 * @ClassName LlsException
 * @Author 划水艺术家
 * @Date 2022/11/17 16:43
 * @Version 1.0
 **/
@Data
@ApiModel(value = "自定义全局异常类")
public class LlsException extends RuntimeException {

    @ApiModelProperty(value = "异常状态码")
    private Integer code;

    /**
     * 通过状态码和错误消息创建异常对象
     * @param message
     * @param code
     */
    public LlsException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    /**
     * 接收枚举类型对象
     * @param
     */
    public LlsException(ResultCode resultCode, String message) {
       this(resultCode.getCode(), message);
    }

    /**
     * 直接接受整个枚举类型对象
     * @param
     */
    public LlsException(ResultCode resultCode) {
        this(resultCode.getCode(), resultCode.getMessage());
    }

    @Override
    public String toString() {
        return "LlsException{" +
                "code=" + code +
                '}';
    }

}
